﻿using System;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

using Xc.DataAccess.Core;
using Xc.DataAccess.HyperTerminalCore.Models;

namespace Xc.DataAccess.HyperTerminalCore.Models
{
    /// <summary>
    /// TCP客户端信息
    /// </summary>
    public interface ITcpClientInfo
    {
        /// <summary>
        /// 对方的IP地址
        /// </summary>
        string IpAddress { get; }
        /// <summary>
        /// 接收个数
        /// </summary>
        int ReceiveCount { get; }
        /// <summary>
        /// 发送个数
        /// </summary>
        int SendCount { get; }
        /// <summary>
        /// TCP客户端信息
        /// </summary>
        TcpClient TcpClient { get; }
        /// <summary>
        /// 收到对方的数据
        /// </summary>

        event Action<byte[], TcpClientInfo,Encoding> ReceiveMessage;
        /// <summary>
        /// 客户端被关闭
        /// </summary>
        event Action<TcpClientInfo> OnClose;
        /// <summary>
        /// 关闭通道
        /// </summary>
        void Close();
        /// <summary>
        /// 接收数据
        /// </summary>
        void BeginRead();
        /// <summary>
        /// 不使用默认接收器，使用自定义接收器验证是否包含指定对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="timeout">接收超时时间</param>
        /// <param name="func"></param>
        /// <returns></returns>
        Task<ResultData<T>> ReadDataByTemplate<T>(int timeout, Func<byte[], ResultData<T>> func) where T:class,new();
        /// <summary>
        /// 发送一包数据
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        Task<Result> Send(byte[] buffer);
        /// <summary>
        /// 发送一包数据
        /// </summary>
        /// <param name="content"></param>
        /// <param name="isAppendLine"></param>
        /// <returns></returns>
        Task<Result> Send(string content, bool isAppendLine);
    }
}